home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_02 / saks / shape.h < prev   
Encoding:
C/C++ Source or Header  |  1994-12-04  |  503 b   |  34 lines

  1. Listing 1 - A polymorphic hierarchy of shapes with a clone function
  2.  
  3. class shape
  4.     {
  5. public:
  6.     virtual shape *clone() const = 0;
  7.     ...
  8.     };
  9.  
  10. class circle : public shape
  11.     {
  12. public:
  13.     shape *clone() const;
  14.     ...
  15.     };
  16.  
  17. shape *circle::clone() const
  18.     {
  19.     return new circle(*this);
  20.     }
  21.  
  22. class rectangle : public shape
  23.     {
  24. public:
  25.     shape *clone() const;
  26.     ...
  27.     };
  28.  
  29. shape *rectangle::clone() const
  30.     {
  31.     return new rectangle(*this);
  32.     }
  33.  
  34.